Concepts, Techniques, Types, and Importance
Memory management is one of the most fundamental responsibilities of an Operating System. Every program requires memory to store instructions and data. Since memory is limited and shared among multiple processes, the operating system must manage it efficiently.
Memory management is the process of allocating, tracking, and freeing main memory (RAM) for processes running in a system. It ensures efficient use of memory and prevents processes from interfering with each other.
The memory hierarchy represents the organization of different storage components based on speed, cost, and capacity. The diagram below shows how memory is arranged from fastest to slowest in a computer system.
The memory hierarchy is designed to achieve a balance between high performance and low storage cost. As we move upward in the hierarchy, memory becomes faster and more expensive but smaller in size. As we move downward, memory becomes slower, cheaper, and larger in capacity.
Registers are the fastest storage units located inside the CPU. They store instructions and data that are currently being executed by the processor.
Cache memory stores frequently accessed data and instructions to reduce the time required to access main memory, thereby improving system performance.
Main memory holds active programs and data. It is volatile in nature and loses its contents when the system is powered off.
Electronic disks provide fast non-volatile storage and are commonly used to store operating systems and applications.
Magnetic disks offer large storage capacity at a lower cost and are widely used for permanent data storage.
Optical disks are removable storage devices mainly used for data distribution and backups.
Magnetic tapes are used for archival purposes where large amounts of data need to be stored for a long duration at minimal cost.
Memory hierarchy allows the operating system to keep frequently used data in fast memory while storing less-used data in slower storage, resulting in better system efficiency and performance.
When a program runs in a computer, the CPU does not directly access the real memory location. Instead, it uses a logical address which is later converted into a physical address.
A logical address is generated by the CPU during program execution. It is a virtual address and does not represent the actual location in memory.
A physical address is the real address in RAM where the data is stored and accessed.
The MMU converts the logical address into a physical address using a base value stored in the relocation register.
Each process is allocated a single continuous block of memory. Although simple, this method suffers from fragmentation. In a computer system, main memory (RAM) is divided into small blocks. When processes are loaded into memory, each process is given a continuous (one after another) space. This method is called contiguous memory allocation.
In the diagram, memory is divided into parts labeled F1 to F9. Different processes are placed inside these blocks:
Processes are divided into parts and stored in different memory locations, improving memory utilization.In a computer system, memory is not always assigned in one continuous block. Sometimes, a process is divided into smaller parts and stored in different locations in RAM. This method is called non-contiguous memory allocation.
In the diagram:
Paging divides memory into fixed-size pages and frames. A page table maps pages to frames,
eliminating external fragmentation.
aging is a memory management technique used to store and access data efficiently. It allows a process to be divided into smaller parts so that memory can be used in a flexible way.
In paging, memory is divided into two parts:
Paging is a memory management method that converts a logical address generated by the CPU into a physical address in main memory. This process helps the operating system use memory efficiently.
The CPU generates a logical address which is divided into two parts:
In this example, the logical address is 13 bits:
The page number is sent to the page table. The page table stores the corresponding frame number where the page is located in RAM.
After finding the frame number, the system combines:
In this example:
Using the physical address, the system accesses the correct frame in main memory and fetches the required data.
Segmentation in Operating System (OS) is a memory management technique where a program is divided into smaller logical parts called segments.
Segmentation divides a program into logical units such as code, data, and stack segments.
Each segment has its own base and limit.
Segmentation means breaking a program into meaningful sections like:
Segmentation is a memory management technique where a logical address generated by the CPU is converted into a physical address using a segment table.
Virtual memory allows execution of programs larger than physical memory by loading only required portions into RAM when needed.
Swapping temporarily moves processes between main memory and secondary storage to free up space for higher-priority processes.
Memory protection ensures that processes access only their allocated memory using hardware and software mechanisms.
Memory management plays a vital role in the performance and reliability of an operating system. By using techniques such as paging, segmentation, and virtual memory, the OS ensures optimal utilization of limited memory resources.